use std::io::prelude::*;
use support::{project, execs};
-use hamcrest::assert_that;
+use hamcrest::{assert_that, existing_file};
fn setup() {}
File::open(&lockfile).unwrap().read_to_string(&mut lock).unwrap();
assert!(lock.contains(metadata.trim()), "{}", lock);
});
+
+test!(preserve_line_endings_issue_2076 {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ authors = []
+ version = "0.0.1"
+ "#)
+ .file("src/main.rs", "fn main() {}")
+ .file("bar/Cargo.toml", r#"
+ [package]
+ name = "bar"
+ authors = []
+ version = "0.0.1"
+ "#)
+ .file("bar/src/lib.rs", "");
+
+ let lockfile = p.root().join("Cargo.lock");
+ assert_that(p.cargo_process("generate-lockfile"),
+ execs().with_status(0));
+ assert_that(&lockfile,
+ existing_file());
+ assert_that(p.cargo("generate-lockfile"),
+ execs().with_status(0));
+
+ let mut lock0 = String::new();
+ {
+ File::open(&lockfile).unwrap().read_to_string(&mut lock0).unwrap();
+ }
+
+ assert!(lock0.starts_with("[root]\n"));
+
+ let lock1 = lock0.replace("\n", "\r\n");
+ {
+ File::create(&lockfile).unwrap().write_all(lock1.as_bytes()).unwrap();
+ }
+
+ assert_that(p.cargo("generate-lockfile"),
+ execs().with_status(0));
+
+ let mut lock2 = String::new();
+ {
+ File::open(&lockfile).unwrap().read_to_string(&mut lock2).unwrap();
+ }
+
+ assert!(lock2.starts_with("[root]\r\n"));
+ assert_eq!(lock1, lock2);
+});